#!/bin/bash

if [ ! -d "$HOME/kubernetes" ]; then
    echo "kubernetes source code does not exist, clone it..."
    git clone https://github.com/kubernetes/kubernetes.git
fi

if [ ! -d "$HOME/cncamp101" ]; then
    echo "cncamp101 source code doest not exist, clone it..."
    git clone https://github.com/cncamp/101.git cncamp101
fi

tmux has-session -t kube
if [ $? != 0 ]; then
    tmux new-session -s kube -n editor -e 'VIM_SERVER_NAME=kube' -d -c $HOME
    tmux send-keys -t kube 'vim --servername kube kubernetes/README.md' C-m
    tmux new-window -t kube -n ranger 'ranger kubernetes cncamp101'
    tmux select-window -t kube:2
fi

if [ -z "$TMUX" ]; then
    tmux -u attach-session -t kube
else
    tmux -u switch-client -t kube
fi
